using Acme.BookStore.EntityFrameworkCore.Configurations;
using Microsoft.EntityFrameworkCore;
using Acme.BookStore.StockManagement;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Acme.BookStore.EntityFrameworkCore
{
    public static class BookStoreDbContextModelCreatingExtensions
    {
        public static void ConfigureBookStore(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            /* Configure your own tables/entities inside here */

            // 应用我们自定义的实体配置
            builder.ApplyConfiguration(new ShopWhereConfiguration());
            builder.ApplyConfiguration(new RfidConfiguration());

            // 配置新增的七个表对应的实体类，确保表名与数据库完全一致（包括大小写）
            builder.Entity<KucunZhuXinxi>(b =>
            {
                b.ToTable("kucunzhutable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.GoodsCode).IsRequired().HasMaxLength(50).HasColumnName("goods_code");
                b.Property(x => x.GoodsName).IsRequired().HasMaxLength(200).HasColumnName("goods_name");
                b.Property(x => x.Status).IsRequired().HasMaxLength(50).HasColumnName("status");
                b.Property(x => x.GoodsType).IsRequired().HasMaxLength(200).HasColumnName("goods_type");
                b.Property(x => x.Specification).IsRequired().HasMaxLength(200).HasColumnName("specification");
                b.Property(x => x.Unit).IsRequired().HasMaxLength(50).HasColumnName("unit");
                b.Property(x => x.Barcode).IsRequired().HasMaxLength(200).HasColumnName("barcode");
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.LocationName).IsRequired().HasMaxLength(200).HasColumnName("location_name");
                b.Property(x => x.CurrentStock).HasColumnName("current_stock");
                b.Property(x => x.StockAmount).HasPrecision(18, 2).HasColumnName("stock_amount");
                b.Property(x => x.ToBeStored).HasColumnName("to_be_stored");
                b.Property(x => x.ToBeShipped).HasColumnName("to_be_shipped");
                b.Property(x => x.AvailableStock).HasColumnName("available_stock");
                b.Property(x => x.AvailableStockAmount).HasPrecision(18, 2).HasColumnName("available_stock_amount");
                b.Property(x => x.InitialStock).HasColumnName("initial_stock");
                b.Property(x => x.FinalStock).HasColumnName("final_stock");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<ChuRuKuLiuShui>(b =>
            {
                b.ToTable("churukuliutable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.IoOrderCode).IsRequired().HasMaxLength(200).HasColumnName("io_order_code");
                b.Property(x => x.IoDate).HasColumnName("io_date");
                b.Property(x => x.BusinessType).IsRequired().HasMaxLength(200).HasColumnName("business_type");
                b.Property(x => x.IoType).IsRequired().HasMaxLength(50).HasColumnName("io_type");
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.InQuantity).HasColumnName("in_quantity");
                b.Property(x => x.OutQuantity).HasColumnName("out_quantity");
                b.Property(x => x.InAmount).HasPrecision(18, 2).HasColumnName("in_amount");
                b.Property(x => x.OutAmount).HasPrecision(18, 2).HasColumnName("out_amount");
                b.Property(x => x.Operator).IsRequired().HasMaxLength(200).HasColumnName("operator");
                b.Property(x => x.Creator).IsRequired().HasMaxLength(200).HasColumnName("creator");
                b.Property(x => x.Department).IsRequired().HasMaxLength(200).HasColumnName("department");
                b.Property(x => x.CreateTime).HasColumnName("create_time");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<KucunFenBu>(b =>
            {
                b.ToTable("kucunfentable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.LocationName).IsRequired().HasMaxLength(200).HasColumnName("location_name");
                b.Property(x => x.CurrentStock).HasColumnName("current_stock");
                b.Property(x => x.AvailableStock).HasColumnName("available_stock");
                b.Property(x => x.ToBeStored).HasColumnName("to_be_stored");
                b.Property(x => x.ToBeShipped).HasColumnName("to_be_shipped");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<HuoPinPiCiGuanLian>(b =>
            {
                b.ToTable("shoppicitable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.GoodsCode).IsRequired().HasMaxLength(50).HasColumnName("goods_code");
                b.Property(x => x.GoodsName).IsRequired().HasMaxLength(200).HasColumnName("goods_name");
                b.Property(x => x.Status).IsRequired().HasMaxLength(50).HasColumnName("status");
                b.Property(x => x.GoodsType).IsRequired().HasMaxLength(200).HasColumnName("goods_type");
                b.Property(x => x.Specification).IsRequired().HasMaxLength(200).HasColumnName("specification");
                b.Property(x => x.Unit).IsRequired().HasMaxLength(50).HasColumnName("unit");
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.LocationName).IsRequired().HasMaxLength(200).HasColumnName("location_name");
                b.Property(x => x.GoodsBarcode).IsRequired().HasMaxLength(200).HasColumnName("goods_barcode");
                b.Property(x => x.CurrentStock).HasColumnName("current_stock");
                b.Property(x => x.BatchNumber).IsRequired().HasMaxLength(200).HasColumnName("batch_number");
                b.Property(x => x.ProductionDate).HasColumnName("production_date");
                b.Property(x => x.ExpiryDate).HasColumnName("expiry_date");
                b.Property(x => x.ShelfLife).HasColumnName("shelf_life");
                b.Property(x => x.RemainingDays).HasColumnName("remaining_days");
                b.Property(x => x.WarnDays).HasColumnName("warn_days");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<ChaKanGuanLian>(b =>
            {
                b.ToTable("lookshoptable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.GoodsCode).IsRequired().HasMaxLength(50).HasColumnName("goods_code");
                b.Property(x => x.GoodsName).IsRequired().HasMaxLength(200).HasColumnName("goods_name");
                b.Property(x => x.GoodsType).IsRequired().HasMaxLength(200).HasColumnName("goods_type");
                b.Property(x => x.Specification).IsRequired().HasMaxLength(200).HasColumnName("specification");
                b.Property(x => x.Unit).IsRequired().HasMaxLength(50).HasColumnName("unit");
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.CurrentStock).HasColumnName("current_stock");
                b.Property(x => x.BatchNumber).IsRequired().HasMaxLength(200).HasColumnName("batch_number");
                b.Property(x => x.ProductionDate).HasColumnName("production_date");
                b.Property(x => x.ExpiryDate).HasColumnName("expiry_date");
                b.Property(x => x.Operation).IsRequired().HasMaxLength(50).HasColumnName("operation");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<LiuShuiGuanLianPiCi>(b =>
            {
                b.ToTable("liushuiguantable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.IoOrderCode).IsRequired().HasMaxLength(200).HasColumnName("io_order_code");
                b.Property(x => x.IoDate).HasColumnName("io_date");
                b.Property(x => x.WarehouseName).IsRequired().HasMaxLength(200).HasColumnName("warehouse_name");
                b.Property(x => x.BusinessType).IsRequired().HasMaxLength(200).HasColumnName("business_type");
                b.Property(x => x.OutQuantity).HasColumnName("out_quantity");
                b.Property(x => x.InQuantity).HasColumnName("in_quantity");
                b.Property(x => x.Creator).IsRequired().HasMaxLength(200).HasColumnName("creator");
                b.Property(x => x.DocumentTime).HasColumnName("document_time");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });

            builder.Entity<KuCunYuJing>(b =>
            {
                b.ToTable("kuyujingtable");
                
                // 将serial_number列映射为Id属性
                b.Property(x => x.Id).HasColumnName("serial_number").HasColumnType("integer");
                
                b.Property(x => x.GoodsCode).IsRequired().HasMaxLength(50).HasColumnName("goods_code");
                b.Property(x => x.GoodsName).IsRequired().HasMaxLength(200).HasColumnName("goods_name");
                b.Property(x => x.Specification).IsRequired().HasMaxLength(200).HasColumnName("specification");
                b.Property(x => x.Unit).IsRequired().HasMaxLength(50).HasColumnName("unit");
                b.Property(x => x.GoodsType).IsRequired().HasMaxLength(200).HasColumnName("goods_type");
                b.Property(x => x.CurrentStock).HasColumnName("current_stock");
                b.Property(x => x.StockLowerLimit).HasColumnName("stock_lower_limit");
                b.Property(x => x.StockUpperLimit).HasColumnName("stock_upper_limit");
                b.Property(x => x.BelowLowerLimit).IsRequired().HasMaxLength(50).HasColumnName("below_lower_limit");
                b.Property(x => x.AboveUpperLimit).IsRequired().HasMaxLength(50).HasColumnName("above_upper_limit");
                
                // 忽略SerialNumber属性，因为它已经映射为Id
                b.Ignore(x => x.SerialNumber);
                
                // 忽略审计字段
                b.Ignore(x => x.CreationTime);
                b.Ignore(x => x.CreatorId);
                b.Ignore(x => x.LastModificationTime);
                b.Ignore(x => x.LastModifierId);
                b.Ignore(x => x.ConcurrencyStamp);
                b.Ignore(x => x.ExtraProperties);
            });
        }
    }
} 